package com.wangcanxuan.www.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * 配置属性读取工具类
 *
 * @author HHLJ
 * @date 2022/03/22
 */
public class PropertiesReaderUtil {
    private static PropertiesReaderUtil pc = null;
    public Properties properties = null;

    private PropertiesReaderUtil(String propertiesFileName) {
        this.loadConfig(propertiesFileName);
    }

    public static void getInstance(String propertiesFileName) {
        if (pc == null) {
            pc = new PropertiesReaderUtil(propertiesFileName);
        }
    }

    public static String getProperty(String name) {
        return pc.properties.getProperty(name);
    }

    private void loadConfig(String propertiesFileName) {
        try(InputStream inputStream = PropertiesReaderUtil.class.getClassLoader().getResourceAsStream(propertiesFileName)) {
            properties = new Properties();
            properties.load(inputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
